package main

import (
	"fmt"
	"time"
)

/**
 * go run -race atomic.go
 */
type atomicInt int

func (a *atomicInt) increment() {
	// atomic.AddInt32()
	*a++
}

func (a *atomicInt) get() int { // 返回int
	return int(*a)
}

// 原子性int操作  go run -race atomic.go
func main() {
	// atomic.AddInt32() 并发安全
	var a atomicInt
	a.increment()
	go func() {
		a.increment()
	}()
	time.Sleep(time.Millisecond)
	fmt.Println(a.get())
}
